use crate::component::Task;
use std::collections::VecDeque;

// TODO: 已完成的, 正在执行的, 失败的队列
// TODO: 设计成 trait, 以后能用 redis 等实现...
pub struct Scheduler<M, ItemType> {
    queue: VecDeque<Task<M, ItemType>>,
}

impl<M, ItemType> Scheduler<M, ItemType> {
    pub fn new() -> Self {
        Self {
            queue: VecDeque::new(),
        }
    }

    pub fn enqueue(&mut self, task: Task<M, ItemType>) {
        self.queue.push_back(task);
    }

    pub fn dequeue(&mut self) -> Option<Task<M, ItemType>> {
        self.queue.pop_front()
    }

    pub fn is_empty(&self) -> bool {
        self.queue.is_empty()
    }

    pub fn extends(&mut self, tasks: Vec<Task<M, ItemType>>) {
        self.queue.extend(tasks);
    }
}
